#include<iostream>
#include<memory>
#include"TcpServer.hpp"
#include"Calculator.hpp"

Calculator cal;
void DefaultOnMessage(std::weak_ptr<Connection> conn)
{
    if(conn.expired()) return;
    auto connection=conn.lock();
    std::cout<<"上层得到了数据："<<connection->Inbuffer()<<std::endl;
    std::string responser_ptr=cal.Handler(connection->Inbuffer());
    if(!responser_ptr.empty())
        return;
    lg(Debug,"%s",responser_ptr.c_str());
    connection->AppendInfo(responser_ptr);
    auto tcpserver=connection->_tcpserver_ptr.lock();
    tcpserver->Sender(connection);
}

int main()
{
    // TcpServer被shared_Ptr管理以后才能用的
    // 才能用shared_from_this()
    std::shared_ptr<TcpServer> svr(new TcpServer(8888,DefaultOnMessage));
    svr->Init();
    svr->Loop();
    return 0;
}